package logic

import (
	"changes/changesrpc/changesrpc"
	"changes/changesrpc/internal/svc"
	"changes/model/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *changesrpc.AddRequest) (*changesrpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	change := mysql.Change{
		Title:  in.Title,
		Num:    int(in.Num),
		Status: in.Status,
		Timed:  in.Timed,
	}

	mysql.DB.Create(&change)

	return &changesrpc.AddResponse{
		Id: int64(change.ID),
	}, nil
}
